#ifndef SESSIONFRIENDAREA_H
#define SESSIONFRIENDAREA_H

#include <QWidget>
#include <QScrollArea>
#include <QStyle>
#include <QScrollBar>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QStyleOption>
#include <QPainter>
#include "./model/debug.h"


enum ItemType {
    SessionItemType,
    FriendItemType,
    ApplyItemType
};


class SessionFriendItem : public QWidget
{
    Q_OBJECT
public:
    SessionFriendItem(QWidget* owner, const QIcon& avatar, const QString&name, const QString &lastMessage);

    void mousePressEvent(QMouseEvent *event) override;
    // 选中这⼀项要做的事情. 单独提出⼀个函数, 为了后续能直接调⽤.
    void select();
    void enterEvent(QEnterEvent* event) override;
    void leaveEvent(QEvent* event) override;
    void paintEvent(QPaintEvent *event) override;
    // 如果该元素被点击时, 要做哪些事情
    virtual void active() { }

protected:
    QGridLayout* layout;
    // 显⽰最后⼀条消息/描述信息
    QLabel* messageLabel;
    // 是否被选中
    bool selected;
    // 该 Item 所属的 QWidget. 此处填写 SessionFriendArea
    QWidget* owner;
};


//////////////////////////////////////////////////////
/// 表⽰整个 会话-好友 区域
//////////////////////////////////////////////////////
class SessionFriendArea : public QScrollArea
{
    Q_OBJECT
public:
    SessionFriendArea();

    void clear();

    // 添加⼀个元素, text 可能表⽰签名, 也可能表⽰最后⼀条消息.
    void addItem(ItemType itemType, const QString& id, const QIcon& avatar,
                 const QString& name, const QString& text);
    // 点击指定下标的元素
    void clickItem(int index);
signals:
private:
    QWidget* container;

};

class SessionItem : public SessionFriendItem {
    Q_OBJECT
private:
    QString chatSessionId;
public:
    SessionItem(QWidget* owner, const QString& chatSessionId, const QIcon&
                                                                  avatar, const QString &name, const QString &lastMessage);
    void active() override;
};

class FriendItem : public SessionFriendItem {
    Q_OBJECT
private:
    QString userId;
public:
    FriendItem(QWidget* owner, const QString& userId, const QIcon& avatar,
               const QString &name, const QString &description);
    void active() override;
};

class ApplyItem : public SessionFriendItem {
    Q_OBJECT
private:
    // 申请⼈的⽤⼾ id
    QString userId;
public:
    ApplyItem(QWidget* owner, const QString& userId, const QIcon& avatar, const
              QString& name);
    void active() override;
};




#endif // SESSIONFRIENDAREA_H
